/**
 */
package ms.unicorn.dsl.unicornDSL.impl;

import java.util.Collection;

import ms.unicorn.dsl.unicornDSL.UnicornDSLPackage;
import ms.unicorn.dsl.unicornDSL.XArray;
import ms.unicorn.dsl.unicornDSL.XExpression;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>XArray</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link ms.unicorn.dsl.unicornDSL.impl.XArrayImpl#isList <em>List</em>}</li>
 *   <li>{@link ms.unicorn.dsl.unicornDSL.impl.XArrayImpl#getExpressions <em>Expressions</em>}</li>
 *   <li>{@link ms.unicorn.dsl.unicornDSL.impl.XArrayImpl#isMap <em>Map</em>}</li>
 *   <li>{@link ms.unicorn.dsl.unicornDSL.impl.XArrayImpl#getKeys <em>Keys</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class XArrayImpl extends XExpressionImpl implements XArray
{
  /**
   * The default value of the '{@link #isList() <em>List</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #isList()
   * @generated
   * @ordered
   */
  protected static final boolean LIST_EDEFAULT = false;

  /**
   * The cached value of the '{@link #isList() <em>List</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #isList()
   * @generated
   * @ordered
   */
  protected boolean list = LIST_EDEFAULT;

  /**
   * The cached value of the '{@link #getExpressions() <em>Expressions</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getExpressions()
   * @generated
   * @ordered
   */
  protected EList<XExpression> expressions;

  /**
   * The default value of the '{@link #isMap() <em>Map</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #isMap()
   * @generated
   * @ordered
   */
  protected static final boolean MAP_EDEFAULT = false;

  /**
   * The cached value of the '{@link #isMap() <em>Map</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #isMap()
   * @generated
   * @ordered
   */
  protected boolean map = MAP_EDEFAULT;

  /**
   * The cached value of the '{@link #getKeys() <em>Keys</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getKeys()
   * @generated
   * @ordered
   */
  protected EList<XExpression> keys;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected XArrayImpl()
  {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return UnicornDSLPackage.Literals.XARRAY;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public boolean isList()
  {
    return list;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setList(boolean newList)
  {
    boolean oldList = list;
    list = newList;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, UnicornDSLPackage.XARRAY__LIST, oldList, list));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<XExpression> getExpressions()
  {
    if (expressions == null)
    {
      expressions = new EObjectContainmentEList<XExpression>(XExpression.class, this, UnicornDSLPackage.XARRAY__EXPRESSIONS);
    }
    return expressions;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public boolean isMap()
  {
    return map;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setMap(boolean newMap)
  {
    boolean oldMap = map;
    map = newMap;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, UnicornDSLPackage.XARRAY__MAP, oldMap, map));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<XExpression> getKeys()
  {
    if (keys == null)
    {
      keys = new EObjectContainmentEList<XExpression>(XExpression.class, this, UnicornDSLPackage.XARRAY__KEYS);
    }
    return keys;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case UnicornDSLPackage.XARRAY__EXPRESSIONS:
        return ((InternalEList<?>)getExpressions()).basicRemove(otherEnd, msgs);
      case UnicornDSLPackage.XARRAY__KEYS:
        return ((InternalEList<?>)getKeys()).basicRemove(otherEnd, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
      case UnicornDSLPackage.XARRAY__LIST:
        return isList();
      case UnicornDSLPackage.XARRAY__EXPRESSIONS:
        return getExpressions();
      case UnicornDSLPackage.XARRAY__MAP:
        return isMap();
      case UnicornDSLPackage.XARRAY__KEYS:
        return getKeys();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @SuppressWarnings("unchecked")
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case UnicornDSLPackage.XARRAY__LIST:
        setList((Boolean)newValue);
        return;
      case UnicornDSLPackage.XARRAY__EXPRESSIONS:
        getExpressions().clear();
        getExpressions().addAll((Collection<? extends XExpression>)newValue);
        return;
      case UnicornDSLPackage.XARRAY__MAP:
        setMap((Boolean)newValue);
        return;
      case UnicornDSLPackage.XARRAY__KEYS:
        getKeys().clear();
        getKeys().addAll((Collection<? extends XExpression>)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case UnicornDSLPackage.XARRAY__LIST:
        setList(LIST_EDEFAULT);
        return;
      case UnicornDSLPackage.XARRAY__EXPRESSIONS:
        getExpressions().clear();
        return;
      case UnicornDSLPackage.XARRAY__MAP:
        setMap(MAP_EDEFAULT);
        return;
      case UnicornDSLPackage.XARRAY__KEYS:
        getKeys().clear();
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case UnicornDSLPackage.XARRAY__LIST:
        return list != LIST_EDEFAULT;
      case UnicornDSLPackage.XARRAY__EXPRESSIONS:
        return expressions != null && !expressions.isEmpty();
      case UnicornDSLPackage.XARRAY__MAP:
        return map != MAP_EDEFAULT;
      case UnicornDSLPackage.XARRAY__KEYS:
        return keys != null && !keys.isEmpty();
    }
    return super.eIsSet(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public String toString()
  {
    if (eIsProxy()) return super.toString();

    StringBuffer result = new StringBuffer(super.toString());
    result.append(" (list: ");
    result.append(list);
    result.append(", map: ");
    result.append(map);
    result.append(')');
    return result.toString();
  }

} //XArrayImpl
